package com.lagou.edu.controller;

import cn.hutool.extra.mail.MailUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@RestController
@RequestMapping("/email")
@Slf4j
public class MailController {

    private ExecutorService executorService = Executors.newSingleThreadExecutor();

    @PostMapping("/{email}/{code}")
    public boolean sendMail(@PathVariable("email") String email, @PathVariable("code") String code){
        try {
            executorService.submit(()->{
                MailUtil.send(email, "你要的注册验证码到了", "注册验证码："+code, false);
            });
        }catch (Exception e){
            log.error("send mail error",e);
            return false;
        }
        return true;
    }
}
